@extends('shared.adminBase')
@section('title','配置权限')
@section('content')
    <section class="content-header" xmlns="http://www.w3.org/1999/html">
        <h1>配置权限</h1>
        <ol class="breadcrumb">
            <li><a href="{{URL::action('AdminController@innerIndex')}}"><i class="fa fa-home"></i> 首页</a></li>
            <li><a href="{{URL::action('AdminController@getManagerRoleList')}}"> 角色管理</a></li>
            <li class="active">配置权限</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <!-- /.box -->
            <div class="box">
                <form action="{{URL::action('AdminController@storePermission')}}" method="post">
                    <div class="box-header"></div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <input type="hidden" name="roleID" value="{{$role->manager_role_id}}">
                        {{csrf_field()}}
                        @foreach($modules as $module)
                            @if($module->layer==1)

                                <div class="checkbox">{{$module->name}}<label>（<input type="checkbox"
                                                                                      onclick="toggleAll(this,'{{$module->manager_module_id}}');">全选）</label>
                                </div>

                                @foreach($modules as $subMod)
                                    @if($module->manager_module_id==$subMod->parent_id)
                                        <input type="hidden" name="moduleID[]" value="{{$subMod->manager_module_id}}">
                                        <dl class="dl-horizontal">
                                            <dt class="text-right">{{$subMod->name}}</dt>
                                            <dd class="checkbox">
                                                @foreach($permissions as $per)
                                                    @if($per->manager_module_id==$subMod->manager_module_id)
                                                        @if(array_key_exists($per->manager_module_id,$modPermission)&&($per->value&$modPermission[$per->manager_module_id])>0)
                                                            <label><input data-role="{{$module->manager_module_id}}"
                                                                          name="permissions[{{$subMod->manager_module_id}}][]"
                                                                          value="{{$per->value}}"
                                                                          type="checkbox"
                                                                          checked="checked">{{$per->name}}</label>
                                                        @else
                                                            <label><input data-role="{{$module->manager_module_id}}"
                                                                          name="permissions[{{$subMod->manager_module_id}}][]"
                                                                          value="{{$per->value}}"
                                                                          type="checkbox">{{$per->name}}</label>
                                                        @endif
                                                    @endif
                                                @endforeach
                                            </dd>
                                            </ul>

                                        </dl>
                                    @endif
                                @endforeach
                            @endif
                        @endforeach

                    </div>
                    <div class="box-footer">
                        <button type="submit" class="btn btn-default">提交</button>
                        <button type="button" onclick="history.back();" class="btn btn-default">返回</button>
                    </div>
                </form>
            </div>
        </div>
    </section>
@endsection
@section('scripts')
    <script type="text/javascript">
        function toggleAll(obj, id) {
            var isChecked = $(obj).is(':checked');
            $('[data-role=' + id + ']').each(function (index, value) {
                $(value).prop("checked", isChecked);
            });
        }
    </script>
@endsection